<#import "../tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="订单管理">
<style>
    .form-horizontal .controls {
        line-height: 40px;
        height: 40px;
    }

    .button-primary,.button-danger {
        margin-left: 5px;
    }

    .form-horizontal .time-label {
        width: 60px;
        line-height: 40px;
        margin-left: 20px;
    }

    .form-horizontal .time-controls {
        margin-left: 5px;
    }
    .form-horizontal .money-label {
        width: 60px;
        line-height: 40px;
        margin-left: 5px;
    }
</style>
<#-----------------------------------------------搜索表单start----------------------------------------->
<form id="searchForm" class="form-panel" action="${basepath}/manage/order/loadData">
    <ul class="panel-content">
        <li>
            <div class="control-group span5">
                <div class="search-controls  controls">
                    <input type="text" name="account" id="title" value="" placeholder="搜索订单号、买家帐号等">
                </div>
            </div>
            <div class="form-actions span2">
                <button type="submit" class="button  button-primary">
                    搜索
                </button>
            </div>
            <div>
                <label class="time-label control-label">订单状态：</label>

                <div class="time-controls controls">
                    <select name="status" class="input-normal" id="status">
                        <option value="">全部</option>
                        <option value="init">待付款</option>
                        <option value="pass">待发货</option>
                        <option value="finish">已完成</option>
                        <option value="send">已发货</option>
                        <option value="cancel">已关闭</option>
                    </select>
                </div>
                <label class="money-label control-label">起始日期：</label>

                <div class="time-controls controls">
                    <input name="startDate" class="input-small calendar" type="text" style="width: 80px;"><label>
                    &nbsp;-&nbsp;</label><input
                        name="endDate" class="input-small calendar" type="text" style="width: 80px;">
                </div>

                <button type="submit" class="button  button-primary">
                    查询
                </button>
                <a class="button button-danger" onclick="return delFunction()">
                    删除
                </a>
            </div>
        </li>

    </ul>
</form>
<#---------------------------------------------------------搜索表单end------------------------------------------>
<div id="grid"></div>
<#---------------------------------------------------------编辑表单start---------------------------------------->
<div id="editContent" style="display: none">
    <form id="editForm" action="${basepath}/manage/order/updateJson" method="post">

    </form>
</div>
<#---------------------------------------------------------编辑表单end------------------------------------------>
<script>
    /*-------------------------------------------------------- 表格数据渲染start-----------------------------------*/
    var Grid = BUI.Grid,
            Store = BUI.Data.Store,
            columns = [
                {title: '订单号', dataIndex: 'id', elCls: 'center'},
                {title: '买家帐号', dataIndex: 'account', elCls: 'center'},
                {title: '商品名称', dataIndex: 'productName', width: 400, elCls: 'center'},
                {title: '单价', dataIndex: 'price', elCls: 'center'},
                {title: '数量', dataIndex: 'number', elCls: 'center'},
                {title: '金额', dataIndex: 'total0', elCls: 'center'},
                {
                    title: '订单状态', dataIndex: 'status', elCls: 'center', renderer: function (data) {
                    if (data == "init")
                        return "待付款";
                    else if (data == "pass")
                        return "待发货";
                    else if (data == "finish")
                        return "已完成";
                    else if (data == "send")
                        return "待收货";
                    else if (data == "cancel")
                        return "已关闭";

                }
                },
                {
                    title: '操作', dataIndex: 'orderDetailId', elCls: 'center', renderer: function (value) {
                    return '<a href="${basepath}/manage/order/toEdit?orderDetailId=' + value + '">查看</a><a style="margin-left:10px;" >删除</a> ';
                }
                }
            ];

    var store = new Store({
                url: 'loadData',
                autoLoad: true, //自动加载数据
                params: { //配置初始请求的参数
                    length: '10',
                    status: $("#status").val()
                },
                pageSize: 3,	// 配置分页数目
                root: 'list',
                totalProperty: 'total'
            }),
            grid = new Grid.Grid({
                render: '#grid',
                columns: columns,
                forceFit: true,
                loadMask: true, //加载数据时显示屏蔽层
                store: store,
                plugins: [Grid.Plugins.CheckSelection], // 插件形式引入多选表格

                // 底部工具栏
                bbar: {
                    pagingBar: true
                }
            });
    grid.render();

    var form = new BUI.Form.HForm({
        srcNode: '#searchForm'
    }).render();

    form.on('beforesubmit', function (ev) {
        //序列化成对象
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;
    });
    /*---------------------------------------------------表格数据渲染 end-------------------------------------------*/
    //删除选中的记录
    function delFunction() {
        var selections = grid.getSelection();
        var ids = new Array();
        for (var i = 0; i < selections.length; i++) {
            ids[i] = selections[i].id.toString()
        }
        $.ajax({
            type: "POST",
            url: "${basepath}/manage/order/deletesJson",
            dataType: "json",
            data: {
                ids: ids
            },
            success: function (data) {
                var obj = form.serializeToObject();
                obj.start = 0; //返回第一页
                store.load(obj);
            }
        });

    }
</script>
</@page.pageBase>